package com.lb.videoplay.activity;

import android.app.Activity;
import android.app.assist.AssistContent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.SPUtils;
import com.lb.videoplay.R;
import com.lb.videoplay.statuslib.StatusUtil;

/**
 * Created by Mr.lb
 * 时间： 2018/11/28
 * 包名： com.lb.videoplay.activity
 * 描述： 启动页面
 */
public class SplashActivity extends Activity{

    private Handler mHandler;
    private MyThread mMyThread;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        // 第二个参数是是否沉浸,第三个参数是状态栏字体是否为黑色
        StatusUtil.setSystemStatus(this, true, true);
        initData();
    }

    private void initData(){
        mHandler = new Handler();
        mMyThread = new MyThread();
        mHandler.postDelayed(mMyThread, 2000);
    }

    private class MyThread implements Runnable {
        @Override
        public void run() {
           boolean user_first=  SPUtils.getInstance().getBoolean("FIRST",true);//判断是否第一次
            if (user_first) {//启动引导界面
                SPUtils.getInstance().put("FIRST", false);
                ActivityUtils.startActivity(GuideActivity.class);
            } else {//跳转页面
                ActivityUtils.startActivity(MainActivity.class);
            }
           ActivityUtils.finishActivity(SplashActivity.this);
        }
    }
    @Override
    public void onProvideAssistContent(AssistContent outContent) {
        super.onProvideAssistContent(outContent);
    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();
        mHandler.removeCallbacks(mMyThread);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //销毁线程
        if (mHandler != null)
            mHandler.removeCallbacks(mMyThread);
    }
}
